/****************************************************
	文件：ResClassObjectPool.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2021/1/1 22:11:52
	功能：资源加载类对象池
*****************************************************/

using HTFW.Core;
using HTFW.Utility.Global;

namespace HTFW.Res
{
    public class ResClassObjectPool : Singleton<ResClassObjectPool>, IDisposable
    {
        ObjectPool<ResData> mResDataPool;
        ObjectPool<IResLoader> mABLoaderPool;
        ObjectPool<IResLoader> mAssetLoaderPool;
        ObjectPool<ILoadResult> mLoadResultPool;

        public void Init()
        {
            mResDataPool = new ObjectPool<ResData>(500, (pool) => { return new ResData(); }, (resData) => { },
                (resData) => { resData.Reset(); });

            mABLoaderPool = new ObjectPool<IResLoader>(100, (pool) => { return new ABLoader(); }, (abLoader) => { },
                (abLoader) => { });

            mAssetLoaderPool = new ObjectPool<IResLoader>(50, (pool) => { return new AssetLoader(); },
                (assetLoader) => { }, (assetLoader) => { });

            mLoadResultPool = new ObjectPool<ILoadResult>(500, (pool) => { return new ResLoadResult(); },
                (result) => { },
                (result) => { });
        }

        public void Dispose()
        {
            mResDataPool.Dispose();
            mABLoaderPool.Dispose();
            mAssetLoaderPool.Dispose();
            mLoadResultPool.Dispose();
        }

        public ResData SpawnResData(bool ignoreCapcity = true)
        {
            return mResDataPool.Spawn(ignoreCapcity);
        }

        public void DespawnResData(ResData resData, bool destory = false)
        {
            mResDataPool.Despawn(resData, destory);
        }

        public IResLoader SpawnABLoader(bool ignoreCapcity = true)
        {
            return mABLoaderPool.Spawn(ignoreCapcity);
        }

        public void DespawnABLoader(IResLoader loader, bool destory = false)
        {
            mABLoaderPool.Despawn(loader, destory);
        }

        public IResLoader SpawnAssetLoader(bool ignoreCapcity = true)
        {
            return mAssetLoaderPool.Spawn(ignoreCapcity);
        }

        public void DespawnAssetLoader(IResLoader loader, bool destory = false)
        {
            mAssetLoaderPool.Despawn(loader, destory);
        }

        public ILoadResult SpawnResLoadResult(bool ignoreCapcity = true)
        {
            return mLoadResultPool.Spawn(ignoreCapcity);
        }

        public void DespawnResLoadResult(ILoadResult loadResult, bool destory = false)
        {
            mLoadResultPool.Despawn(loadResult, destory);
        }
    }
}